package dhm.com.hpx.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import dhm.com.hpx.R;
import dhm.com.hpx.base.netWork.Constant;
import dhm.com.hpx.entity.GetExtensionListBean;
import dhm.com.hpx.utils.SpUtils;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class ExtensionAdapter extends RecyclerView.Adapter<ExtensionAdapter.ViewHolder>{

    private Context context;


    List<GetExtensionListBean.DataBean> list = new ArrayList<>();


    private String uid;


    public ExtensionAdapter(Context context) {
        this.context = context;
        uid= SpUtils.getString(context,"uid");
    }


    public void setList(List<GetExtensionListBean.DataBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view = LayoutInflater.from(context).inflate(R.layout.item_extension, null);
        viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int i) {
        viewHolder.image.setImageURI(Constant.PATH+list.get(i).getCover_pic());
        viewHolder.title.setText(list.get(i).getTitle());
        viewHolder.platform_name.setText(list.get(i).getPlatform_name());
        viewHolder.time.setText(list.get(i).getCreate_time());
        if (list.get(i).getType()==1){
            viewHolder.radio_see.setVisibility(View.GONE);
        }else {
            viewHolder.radio_see.setVisibility(View.VISIBLE);
        }

        if (uid.equals(list.get(i).getUser_id()+"")){
            viewHolder.del.setVisibility(View.VISIBLE);
        }else {
            viewHolder.del.setVisibility(View.GONE);
        }

        viewHolder.rela.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClick.item(i);
            }
        });

        viewHolder.del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onIntentClick.item(i);
            }
        });

    }



    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public SimpleDraweeView image;
        public TextView title;
        public TextView platform_name;
        public TextView time;
        public TextView del;
        public ImageView radio_see;
        public RelativeLayout rela;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            image = itemView.findViewById(R.id.image);
            rela = itemView.findViewById(R.id.rela);
            title = itemView.findViewById(R.id.title);
            platform_name = itemView.findViewById(R.id.platform_name);
            time = itemView.findViewById(R.id.time);
            radio_see = itemView.findViewById(R.id.radio_see);
            del = itemView.findViewById(R.id.del);
        }
    }

    private OnClick onClick;

    public void setdeleteClick(OnClick onClick) {
        this.onClick = onClick;
    }

    public interface OnClick {
        void item(int posttion);
    }

    private OnIntentClick onIntentClick;

    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }

    public interface OnIntentClick {
        void item(int position);
    }


}

